<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>修改学生信息</legend>
            </fieldset>

            <form class="layui-form" action="" lay-filter="studentForm">
                <input type="hidden" name="student_id"/>
                <div class="layui-form-item">
                    <label class="layui-form-label">学生姓名</label>
                    <div class="layui-input-block">
                        <input id="student_name" type="text" name="student_name" lay-verify="title" autocomplete="off"
                            placeholder="请输入姓名" class="layui-input" value="">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">学生性别</label>
                    <div class="layui-input-block">
                        <input id="student_sex" type="radio" name="student_sex" value="男" title="男" checked="">
                        <input id="student_sex" type="radio" name="student_sex" value="女" title="女">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">学生年龄</label>
                    <div class="layui-input-block">
                        <input  id="student_age" type="text" name="student_age" lay-verify="title" autocomplete="off" placeholder="请输入年龄"
                            class="layui-input" value="">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">学生身份ID</label>
                    <div class="layui-input-block">
                        <input  id="student_NID" type="text" name="student_NID" lay-verify="title" autocomplete="off"
                            placeholder="请输入身份证ID" class="layui-input" value="">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">学生电话</label>
                    <div class="layui-input-block">
                        <input  id="student_phone" type="tel" name="student_phone" lay-verify="required|student_phone" autocomplete="off"
                            class="layui-input" value="">
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">家庭住址</label>
                    <div class="layui-input-block">
                        <textarea id="student_address" name="student_address" placeholder="请输入详细家庭住址" class="layui-textarea" aria-valuetext=""></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="demo1">立即修改</button>
                        <!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
                    </div>
                </div>
            </form>
        </div>
    </div>
    <script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script>
        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer,
                $ = layui.$;

                var jsonStr = localStorage.getItem("student");
                var stuObj = JSON.parse(jsonStr);

                form.val("studentForm",{
                    student_id: stuObj.student_id,
                    student_name: stuObj.student_name,
                    student_sex: stuObj.student_sex,
                    student_age: stuObj.student_age,
                    student_NID: stuObj.student_NID,
                    student_address: stuObj.student_address,
                    student_phone: stuObj.student_phone
                })
            //监听提交
            form.on('submit(demo1)', function (data) {
                data = data.field;
                $.ajax({
                        url: "http://localhost:8080/day58_ssm/Student/editStudent",
                        data: data,
                        type: "POST",
                        dataType: "json",
                        success: function (resultInfo) {
                            if (resultInfo.flag) {
                                layer.alert(resultInfo.errorMsg,{title:"温馨提示"},function(){
                                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(iframeIndex);
                                })
                            } else {
                                layer.alert(resultInfo.errorMsg,{title:"温馨提示"},function(){
                                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(iframeIndex);
                                })
                            }
                        }
                    });
                return false;
            });
        });
    </script>
</body>
</html>